import { SafeAny, SafeTimer } from "../core/types/Safe";

export function debounce<T extends (...args: SafeAny[]) => void>(
    func: T,
    delay: number
): (...args: Parameters<T>) => void {
    let timer: SafeTimer | null = null;

    return (...args: Parameters<T>): void => {
        if (timer) {
            clearTimeout(timer); // 清除之前的定时器
        }
        timer = setTimeout(() => {
            func(...args); // 延迟执行函数
        }, delay);
    };
}


export function generateUniqueString() {
    return Date.now().toString(36) + Math.random().toString(36).substr(2, 8);
}